<?php

declare(strict_types=1);

namespace app\common\model;

use think\Model;
use think\response\Json;

use app\common\model\DistrictPro as DistrictProModel;
/**
 * @mixin \think\Model
 */
class District extends Base
{

    protected $name = 'district';
    
    public static function districtSelect()
    {
        parent::startTrans();
        try {
            $find = parent::where(['is_del'=>0])->order('sort asc')->field('id,title')->select()->toArray();
            if(empty($find)){
                return [];
            }
            foreach($find as $k=>$v){
                $data[$v['id']]=$v['title'];
            }
            return  $data;
        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }
    public static function _save($param)
    {
        parent::startTrans();
        try {
            if (isset($param['id']) && $param['id']) {
                parent::update($param);
                $district_id = $param['id'];
            } else {
                $desc = parent::create($param);
                $district_id = $desc->id;
            }
            // DistrictProModel::districtAll($district_id);
            parent::commit();
            return ['code' => 1, 'msg' => '操作成功'];
        } catch (\Exception $e) {
            parent::rollback();
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }
}
